<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>lesson 3</title>
    <script src="https://unpkg.com/vue@next"></script>
</head>

<body>
    <div id="root"> </div>
</body>
<!-- 第一章 vue初探/1-4编写TodoList小功能，了解循环和双向绑定 -->
</html>
<script>
    Vue.createApp({
        data() {
            return {
                value: "",//初始化vallue值
                List: [],//定义一个数组
            };
        },
        methods: {
            handleAddItem() {
                // 进行非空判断
                if (this.value === "") {
                    alert("内容不能为空");
                    return false;
                } else {
                    // 添加所需要的的内容
                    this.List.push(this.value);
                    // 将输入框内容全部清空
                    this.value = ""
                }

            },
        },
        template:
            `
            <div>
                <input placeholder="请输入内容" v-model="value" @keyup.enter="handleAddItem"/>
                <button v-on:click="handleAddItem">增加</button>
                 <ul>
                    <li v-for="item,index in List">{{item}}  {{index}}</li>
                 </ul>    
            </div>
            `
    }).mount('#root')
</script>